# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=qt6-base
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
_qtver=6.0.3
pkgver=${_qtver/-/}
pkgrel=1
arch=(any)
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://www.qt.io'
license=(GPL3 LGPL3 FDL custom)
pkgdesc="A cross-platform application and UI framework (mingw-w64)"
depends=("${MINGW_PACKAGE_PREFIX}-double-conversion"
         "${MINGW_PACKAGE_PREFIX}-dbus"
         "${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-fontconfig"
         "${MINGW_PACKAGE_PREFIX}-icu"
         "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
         "${MINGW_PACKAGE_PREFIX}-pcre2"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-sqlite3"
         "${MINGW_PACKAGE_PREFIX}-zlib")
optdepends=("${MINGW_PACKAGE_PREFIX}-libmariadbclient"
            "${MINGW_PACKAGE_PREFIX}-firebird2"
            "${MINGW_PACKAGE_PREFIX}-postgresql")
conflicts=("${MINGW_PACKAGE_PREFIX}-qt5"
           "${MINGW_PACKAGE_PREFIX}-qt5-debug"
           "${MINGW_PACKAGE_PREFIX}-qt5-static")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-xmlstarlet"
             "${MINGW_PACKAGE_PREFIX}-libmariadbclient"
             "${MINGW_PACKAGE_PREFIX}-firebird2"
             "${MINGW_PACKAGE_PREFIX}-postgresql")
groups=(${MINGW_PACKAGE_PREFIX}-qt6)
_pkgfn="${_realname/6-/}-everywhere-src-${_qtver}"
source=("https://download.qt.io/official_releases/qt/${pkgver%.*}/$_qtver/submodules/$_pkgfn.tar.xz")
sha256sums=('1a45b61c2a349964625c50e3ea40cbb309e269762dd0786397e0e18e7e10d394')

build() {
  cd ${srcdir}
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -GNinja \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DINSTALL_INCLUDEDIR=include/qt6 \
    -DINSTALL_ARCHDATADIR=share/qt6 \
    -DINSTALL_DATADIR=share/qt6 \
    -DINSTALL_MKSPECSDIR=share/qt6/mkspecs \
    -DINSTALL_DESCRIPTIONSDIR=share/qt6/modules \
    -DQT_FEATURE_system_doubleconversion=ON \
    -DQT_FEATURE_system_freetype=ON \
    -DQT_FEATURE_system_jpeg=ON \
    -DQT_FEATURE_system_pcre2=ON \
    -DQT_FEATURE_system_png=ON \
    -DQT_FEATURE_system_sqlite=ON \
    -DQT_FEATURE_system_zlib=ON \
    -DQT_FEATURE_openssl=ON \
    -DQT_FEATURE_opengl=ON \
    -DQT_FEATURE_opengl_desktop=ON \
    -DQT_FEATURE_dbus=ON \
    -DQT_FEATURE_icu=ON \
    -DQT_FEATURE_fontconfig=ON \
    -DQT_FEATURE_pkg_config=ON \
    ../${_pkgfn}

  ninja
}

package() {
  DESTDIR=${pkgdir} cmake --install build-${MINGW_CHOST}

  install -d "$pkgdir${MINGW_PREFIX}"/share/licenses/${_realname}
  install -Dm644 $_pkgfn/LICENSE* -t "$pkgdir${MINGW_PREFIX}"/share/licenses/${_realname}
}
